package com.fengpanlong.service;

import java.util.ArrayList;
import java.util.List;

import com.fengpanlong.dao.IdeaDao;
import com.fengpanlong.dao.ProjectDao;
import com.fengpanlong.entity.Employee;
import com.fengpanlong.entity.Idea;
import com.fengpanlong.entity.Project;
import com.fengpanlong.util.IdeaHelp;
import com.fengpanlong.util.Pager;

public class PagerService {
	/**
	 * 工程分页
	 * @param num
	 * @param employeeId
	 * @return
	 */
	public static Pager<Project> findPagerOfProjectsByEmployeeId(int num, String employeeId) {
		ProjectDao pd  = new ProjectDao();
		return pd.findPagerOfProjectsByEmployeeId(num, employeeId);
	}
	/**
	 * 想法分页
	 * @param num
	 * @param projectId
	 * @return
	 */
	public static Pager<IdeaHelp> findPagerOfProjectsByProjectId(int num,
			String projectId) {
		IdeaDao id = new IdeaDao();
		Pager<Idea> pager =  id.findPagerOfProjectsByProjectId(num,projectId);
		if(pager == null) {
			return null;
		}
		List<IdeaHelp> ideaHelpList = new ArrayList<IdeaHelp>();
		List<Idea> ideaList = pager.getResult();
		for(Idea idea : ideaList) {
			Employee employee = EmployeeService.findEmployeeByEmployeeId(idea.getEmployeeId());
			IdeaHelp ideaHelp = new IdeaHelp();
			ideaHelp.setIdea(idea);
			ideaHelp.setEmployeeName(employee.getUsername());
			ideaHelp.setIdeaId(idea.getId());
			ideaHelpList.add(ideaHelp);
		}
		Pager<IdeaHelp> pager2 = new Pager<IdeaHelp>(pager.getTotalCount(),num);
		pager2.setResult(ideaHelpList);
		return pager2;
		
	}
}
